//
//  WJSubTagCell.m
//  BeDeJie
//
//  Created by jerry on 2017/1/27.
//  Copyright © 2017年 jerry. All rights reserved.
//

#import "WJSubTagCell.h"
#import <UIImageView+WebCache.h>

@interface WJSubTagCell()

@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameView;
@property (weak, nonatomic) IBOutlet UILabel *numView;

@end

@implementation WJSubTagCell

//分隔线处理步骤二：把tableView背景色设置为分割线的背景色
- (void) setFrame:(CGRect)frame {
    frame.size.height -= 1;
    //此时才真正给cell赋值
    [super setFrame:frame];
}

- (void) setItem:(WJSubTagItem *)item {
    _item = item;
    
    _nameView.text = item.theme_name;
    _numView.text = [self resolveNum];
    [_iconView sd_setImageWithURL:[NSURL URLWithString:item.image_list]
                 placeholderImage:[UIImage imageNamed:@"icon_default_user"]
                          options:SDWebImageCacheMemoryOnly
                        completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//                              _iconView.image = [UIImage circleImageWithOriginal:image];
                          }];

}

-(NSString *) resolveNum {
    NSString *numStr = [NSString stringWithFormat:@"%@人订阅", _item.sub_number];
    NSInteger num = _item.sub_number.integerValue;
    if(num > 10000){
        CGFloat numFloat = num / 10000.0;
        numStr = [NSString stringWithFormat:@"%.1f万人订阅", numFloat];
        numStr = [numStr stringByReplacingOccurrencesOfString:@".0" withString:@""];
    }
    return numStr;
}

-(void) awakeFromNib {
    //设置圆角头像，ios9已修复此种方式的bug
    _iconView.layer.cornerRadius = 30;
    _iconView.layer.masksToBounds = YES;
    
//    self.layoutMargins = UIEdgeInsetsZero;
}

@end
